<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="申请名称" >
        <el-input
          v-model="queryParams.pickName"
          placeholder="请输入申请名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="申请月份" >
        <el-date-picker
          v-model="queryParams.planMonth"
          type="month"
          format="yyyy-MM"
          value-format="yyyy-MM"
          size="small"
          placeholder="选择月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="战线区队" >
          <el-select size="small" v-model="queryParams.wnameSJ" placeholder="请选择区队战线" ref="selectReport">
            <el-option :value="queryParams.depId" :label="queryParams.deptName" style="width:199px;height:200px;overflow: auto;background-color:#fff">
              <el-tree
                highlight-current
                :data="reportData"
                :props="defaultProps"
                 accordion
                @node-click="handleNodeClickSJ"
              ></el-tree>
            </el-option>
          </el-select>
      </el-form-item>
       <el-form-item label="审核状态" >
        <el-select
          v-model="queryParams.auditSteps"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="(item,index) in shZT"
            :key="index"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="审核状态"   property="auditSteps" :show-overflow-tooltip="true" width="100" >
        <template slot-scope="scope" style="text-align: center">
          <!-- <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps=='1'">未提交</div> -->
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps=='2'">待审核</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps=='3'">驳回</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps=='4'">通过</div>

        </template>
      </el-table-column>
      <el-table-column align="center" label="申请名称"  property="pickName" width="100" ></el-table-column>
      <el-table-column align="center" label="用途" property="useing" :show-overflow-tooltip="true"  width="200"></el-table-column>
      <el-table-column align="center" label="部门名称"  property="depName"   width="150"></el-table-column>
      <el-table-column align="center" label="申请月份"  property="planMonth" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="领料仓库"  property="waName" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="申请日期"  property="crtTime" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="备注"  property="note" :show-overflow-tooltip="true" ></el-table-column>

      <el-table-column
        label="操作"
        align="center"
        width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            icon="el-icon-s-unfold"
            @click="xingqing(scope.row)">详情</el-button>
          <el-button
            size="mini"

            v-show="scope.row.auditSteps==2"
            type="primary"
            icon="el-icon-guide"
            @click="handleDelete(scope.$index, scope.row)">发放</el-button>
          <el-button
            size="mini"
            type="danger"
            v-show="scope.row.auditSteps=='2'"

            icon="el-icon-close"
            @click="bohui(scope.row)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />

    <kucun-Dialog v-if="kucunShow" :jihuaData="kuncunData" @callback="kucunBack"></kucun-Dialog>
  </div>
</template>

<script>
  import request from '@/utils/request'
  import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
  import kucunDialog from "./kucunDialog";


  export default {
    name: "Role",
    components:{
      kucunDialog
    },
    data() {
      return {
        //记录分页数据
        localPage:undefined,
        localSize:undefined,
        //战线区队信息
        reportData:[],
        //审核状态
        shZT:[
          // {value:'1',label:'未提交'},
          {value:'2',label:'待审核'},
          {value:'3',label:'驳回'},
          {value:'4',label:'通过'},
        ],
        kuncunData:{},
        kucunShow:false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 表格数据
        roleList: [ ],
        // 日期范围
        dateRange: [],
        //科室
        keshiList:[
          { value: '1',label: '科室1'},
          { value: '2',label: '科室2'},
          { value: '3',label: '科室3'},
        ],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},
          { value: '3',label: '未提交'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          pickName: '',
          planMonth: '',
          auditSteps:'2',
          depId:0,
          wnameSJ:'全部'
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "deptName"
        },
      };
    },
    created() {
      var myDate = new Date();
      var yue = myDate.getMonth()+1
      if(yue<9){
        yue = '0'+yue
      }

      this.queryParams.planMonth =  myDate.getFullYear()+'-'+ yue+'';
      this.jlPage()
      this.getZhanxin()
      this.search()

    },
    methods: {
      bohui:function(row){
        this.$confirm('确认要驳回吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.bohuiBtn(row)

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
         //记录页码数据
      jlPage () {
      this.localSize = this.$route.query.size
      this.localPage = this.$route.query.page
      console.log(this.$route.query.page)
      if(this.localPage!==undefined) {
          this.queryParams.pageNum = this.localPage
          console.log(111)
      }
      if(this.localSize!==undefined) {
        this.queryParams.pageSize = this.localSize
      }
      },
      //战线区队更改
      handleNodeClickSJ:function(node){
        console.log(node,'node')
        this.queryParams.depId = node.deptId
        this.queryParams.wnameSJ = node.deptName
        this.$refs.selectReport.blur()
        console.log(this.queryParams)
        this.search()
      },
      //获取站线数据
      getZhanxin:function(){
        request({
          url: 'system/dept/treeselectNoTeam',
          method: 'get',
        }).then(response => {
          this.reportData = response.data
          console.log(this.reportData)
          this.reportData.unshift(
            {deptId:0,deptName:'全部'}
          )
        });
      },
      bohuiBtn:function(row){
        request({
          url: '/material/apply/audit',
          method: 'put',
          data: {
            id:row.id,
            auditSteps:5
          }
        }).then(response => {
          this.$message({
            type: 'success',
            message: '驳回成功!'
          });
        });
      },
      //转换时间戳
      zhuanhuanDate:function(row){

        var oldTime = new Date(row)
        var year=oldTime.getFullYear();
        var month=oldTime.getMonth()+1;
        var date=oldTime.getDate();
        var pp = year+'-'+month+'-'+date
        return  pp
      },
      //详情点击
      xingqing:function(row){
        var pp={
          row:row
        }
        this.$router.push({path:'/suppliesLLGL/shglXQ',query:{pp,page:this.localPage,size:this.localSize}});
      },
      //新增
      cgjhadd:function () {
        var pp={
          name:'新增物料'
        }
        this.kuncunData = pp
        this.kucunShow=true

      },
      //库存管理返回
      kucunBack:function(row){
        this.kucunShow = false
        console.log('返回数据',row)

      },
      //查询
      search:function(){
        this.loading = true
        this.localPage = this.queryParams.pageNum
        this.localSize = this.queryParams.pageSize
        request({
          url: '/material/apply/listAudit',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          console.log(this.roleList)
          for (var i=0;i<this.roleList.length;i++){
            if(this.roleList[i].crtTime){
              this.roleList[i].crtTime = this.zhuanhuanDate(this.roleList[i].crtTime)
            }

          }
          this.total = response.total
        });
      },
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
          response => {
            this.roleList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      //表格编辑
      handleEdit:function (index,row) {
        var pp={
          name:'编辑物料'
        }
        this.kuncunData = pp
        this.kucunShow=true
      },
      //发放
      handleDelete:function (index,row) {
        this.$confirm('确认要发放吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.tijiaoBtn(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消发放'
          });
        });
      },
      tijiaoBtn:function(row){
        request({
          url: '/material/apply/audit',
          method: 'put',
          data: {
            id: row.id,
            auditSteps:4
          }
        }).then(response => {
          this.$message({
            type: 'success',
            message: '发放成功!'
          });
          this.search()

        });

      },

    }
  };
</script>
